package com.htgd.gardenexpo.controller;


import com.github.pagehelper.PageInfo;
import com.htgd.gardenexpo.dto.GeConCompetitionSportsDTO;
import com.htgd.gardenexpo.entity.CommonResult;
import com.htgd.gardenexpo.entity.GeConCompetitionSports;
import com.htgd.gardenexpo.entity.PageQuery;
import com.htgd.gardenexpo.page.CompetitionSportsQuery;
import com.htgd.gardenexpo.page.MarathonListQuery;
import com.htgd.gardenexpo.page.PageBase;
import com.htgd.gardenexpo.service.GeConCompetitionSportsService;
import com.htgd.gardenexpo.vo.CompetitionSportsNumsVO;
import com.htgd.gardenexpo.vo.GeConCompetitionSportsVO;
import com.htgd.gardenexpo.vo.MarathonDetailsVO;
import com.htgd.gardenexpo.vo.MarathonListVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 赛事运动 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-09-21
 */
@RestController
@RequestMapping("/api/competitionSports")
@Api(tags = "赛事运动")
@Slf4j
public class GeConCompetitionSportsController {

    @Autowired
    private GeConCompetitionSportsService geConCompetitionSportsService;

    @PostMapping(value = "/add")
    @ApiOperation("添加")
    public CommonResult add(@RequestBody GeConCompetitionSportsDTO geConCompetitionSportsDTO) {
        log.info("赛事-添加：{}",geConCompetitionSportsDTO);
        return geConCompetitionSportsService.insert(geConCompetitionSportsDTO);
    }

    @PostMapping(value = "/edit")
    @ApiOperation("编辑")
    public CommonResult edit(@RequestBody GeConCompetitionSportsDTO geConCompetitionSportsDTO) {
        log.info("赛事-修改：{}",geConCompetitionSportsDTO);
        return geConCompetitionSportsService.edit(geConCompetitionSportsDTO);
    }

    @DeleteMapping(value = "/delete")
    @ApiOperation("删除")
    public CommonResult delete(String id) {
        log.info("赛事-删除：{}",id);
        return geConCompetitionSportsService.delete(id);
    }

    @GetMapping(value = "/list")
    @ApiOperation("查询")
    public CommonResult<List<GeConCompetitionSportsVO>> list(CompetitionSportsQuery competitionSportsQuery) {
        log.info("赛事-列表查询：{}",competitionSportsQuery);
        PageInfo<GeConCompetitionSportsVO> list = geConCompetitionSportsService.pageList(competitionSportsQuery);
        return CommonResult.success(String.valueOf(list.getTotal()),list.getList());
    }

    @GetMapping(value = "/details")
    @ApiOperation("详情")
    public CommonResult<GeConCompetitionSportsVO> details(String id, HttpServletRequest request) {
        log.info("赛事-详情:{},{}",id,request);
        GeConCompetitionSportsVO geConCompetitionSportsVO = geConCompetitionSportsService.getDetailsById(id,request);
        return CommonResult.success("查询成功",geConCompetitionSportsVO);
    }

    @PostMapping(value = "/review")
    @ApiOperation("审核")
    public CommonResult review(@RequestBody GeConCompetitionSports geConCompetitionSports) {
        log.info("赛事-审核：{}",geConCompetitionSports);
        return geConCompetitionSportsService.review(geConCompetitionSports);
    }

    @GetMapping(value = "/getEntryNums")
    @ApiOperation("获取累计报名人数及赛事参赛情况")
    public CommonResult<List<CompetitionSportsNumsVO>> getEntryNums(@RequestParam(name = "pageNum",required = true,defaultValue = "1")Integer pageNum,
                                                                    @RequestParam(name = "pageSize",required = true,defaultValue = "10")Integer pageSize,
                                                                    @RequestParam(name = "startTime",required = false)String startTime,
                                                                    @RequestParam(name = "endTime",required = false)String endTime,
                                                                    @RequestParam(name = "startDate",required = false)String startDate,
                                                                    @RequestParam(name = "endDate",required = false)String endDate,
                                                                    @RequestParam(name = "type",required = false)String type,
                                                                    @RequestParam(name = "orderBy",required = false,defaultValue = "DESC")String orderBy
                                                                    ) {
        log.info("综管-获取累计报名人数及赛事参赛情况:{},{},{},{},{},{},{},{}",pageNum,pageSize,startTime,endTime,startDate,endDate,type,orderBy);
        return geConCompetitionSportsService.getEntryNums(pageNum,pageSize,startTime,endTime,startDate,endDate,type,orderBy);
    }

    @GetMapping(value = "/marathonList")
    @ApiOperation("甲板马拉松列表")
    public CommonResult<List<MarathonListVO>> marathonList(MarathonListQuery marathonListQuery) {
        log.info("赛事运动-甲板马拉松列表：{}",marathonListQuery);
        PageInfo<MarathonListVO> list = geConCompetitionSportsService.marathonList(marathonListQuery);
        return CommonResult.success(String.valueOf(list.getTotal()),list.getList());
    }

    @GetMapping(value = "/marathonDetails")
    @ApiOperation("甲板马拉松详情")
    public CommonResult<MarathonDetailsVO> marathonDetails(String id) {
        log.info("赛事运动-甲板马拉松详情：{}",id);
        MarathonDetailsVO marathonDetails = geConCompetitionSportsService.marathonDetails(id);
        return CommonResult.success("查询成功",marathonDetails);
    }
}
